<?php 
set_time_limit(0);
$root=preg_replace('/cron$/', '', dirname(__FILE__));

require_once($root."inc.config.php");

require_once($root."initialize.php");

if(($db_msg=cron_initialize()) !== true){

	print_r("Connection error");

}else{ 
	mysql_query("truncate gg_bill");
	mysql_query("truncate gg_earn");

	$sql = "INSERT INTO gg_bill (name,total_bill) SELECT gg_users.name, (sum(gg_purchase.amount)/6000) as total_bill FROM gg_users INNER JOIN gg_purchase ON gg_purchase.uid=gg_users.id AND gg_purchase.status='confirmed' GROUP by gg_users.name";
	mysql_query($sql);

	$sql = "INSERT INTO gg_earn (name,total_earn) SELECT gg_users.name, sum(m1+m2+m3+s+j+w) as total_earn FROM gg_users INNER JOIN gg_member_comm_sum ON gg_member_comm_sum.uid=gg_users.id GROUP BY gg_users.name";
	mysql_query($sql);
	
	print_r("Recalculate Share Done");
}
?>